package com.foxconn.AppDownload.interceptor;

import com.foxconn.AppDownload.domain.AppMenu;
import com.foxconn.AppDownload.util.Consts;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author zengdong
 * @version 1.0
 * @date 2024/1/3 13:49
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        HttpSession session = httpServletRequest.getSession();
        Integer appId = (Integer) session.getAttribute(Consts.LOGIN_EVIDENCE);
        //如果用户没有登录则跳转到登录页面
        if (appId==null){
            httpServletResponse.sendRedirect(httpServletRequest.getContextPath());///cd_crm_war_exploded
            System.out.println("我被攔截了！");
            return false;//停止访问目标资源
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}